module one {

	let options: { [key: string]: string } = {};
	export let getOption = (key: string) => {
		let value: string = options[key];
		if (value) {
			return value;
		}

		value = getSchemeOption(key);
		if (value) {
			return value;
		}

		if (egret.Capabilities.runtimeType == egret.RuntimeType.WEB) {
			value = getCookie(key);
			if (value) {
				return value;
			}
		}

		return egret.getOption(key);
	}

	export function setOption(key: string, value: string): void {
		options[key] = value;
	}

	function getSchemeOption(key: string): string {
		let schemeUrl: string = egret.getOption("schemeUrl");
		if (schemeUrl && schemeUrl.length > 0) {
			let idx: number = schemeUrl.indexOf("?");
			let search: string = schemeUrl.substr(idx + 1);
			let searchArr = search.split("&");
			let length = searchArr.length;
			for (let i: number = 0; i < length; i++) {
				let str = searchArr[i];
				let arr = str.split("=");
				if (arr[0] == key) {
					return arr[1];
				}
			}
		}

		return null;
	}
}